import type { EntityDto } from '@/models/entity';
import type { PagedResultDto } from '@/models/paged-result';
import type { MenuRoleOutputDto, RoleDto, RoleResultDto, RoleResultRequestDto } from '@/models/role';
import type { PermissionInputDto, RolePermissionDto } from '@/models/role-permissions';
import { httpApi } from '@/utils/axios/http';
import url from '@/utils/axios/url';

export function getRolesApi(input: RoleResultRequestDto): Promise<PagedResultDto<RoleResultDto>> {
    return httpApi.httpGet({ url: url.role, params: input });
}

export function getRoleApi(id: number): Promise<RoleResultDto> {
    return httpApi.httpGet({ url: url.role + '/' + id });
}

export function postRoleApi(input: RoleDto): Promise<RoleResultDto> {
    return httpApi.httpPost({ url: url.role, params: input });
}


export function putRoleApi(input: RoleDto): Promise<RoleResultDto> {
    return httpApi.httpPut({ url: url.role, params: input });
}

export function deleteRoleApi(id: number): Promise<EntityDto> {
    return httpApi.httpDelete({ url: url.role + '/' + id });
}

export function getPermissionsApi(code: string): Promise<MenuRoleOutputDto> {
    return httpApi.httpGet({ url: url.role + '/permissions', params: { roleCodes: code } })
}

export function givePermissionsApi(input: PermissionInputDto): Promise<Array<RolePermissionDto>> {
    return httpApi.httpPost({ url: url.role + '/givePermissions', params: input })
}